package com.carhailing.coupons.controller;

import com.alipay.api.AlipayApiException;
import com.carhailing.common.config.AlipaySign;
import com.carhailing.common.exception.BusinessException;
import com.carhailing.coupons.service.CouponsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @Author: Gd
 * @package: com.carhailing.coupons.controller
 * @Project: Online_Taxi_Project
 * @Name: CouponsOrderController
 * @Date: 2024-7-28 21:37
 */
@RestController
public class CouponsOrderController {


    @Autowired
    private CouponsOrderService couponsOrderService;;

    /**
     * 订单支付
     */
    @PostMapping("couponsOrderPay")
    public String paySeckillOrder(@RequestBody AlipaySign alipaySign) throws BusinessException {
//    public String paySeckillOrder(@RequestParam("orderNumber") Long orderNumber, @RequestParam("type") String type) throws Exception{
        return couponsOrderService.paySeckillOrder(alipaySign);
//        return couponsOrderService.paySeckillOrder(orderNumber,type);
    }

    /**
     * 支付回调
     */
    @PostMapping("payNotity")
    public void payNotity(HttpServletRequest request) throws BusinessException, AlipayApiException, UnsupportedEncodingException {
        couponsOrderService.payNotity(request);
    }

    /**
     * 退款
     */
    @GetMapping("refund")
    public void refund(@RequestParam("orderNumber") Long orderNumber, @RequestParam("type") String type) throws Exception {
        couponsOrderService.refund(orderNumber,type);
    }




}
